define(function(require,exports,module){

	//检测类
	var Auth = require('qd-auth-1.0');


	var tpl = require('../../tpl/borrow_repayment.tpl');//载入tpl模板
	//初始化显示表格、搜索
	if(window.location.search.indexOf('borrowId'))
	{
		require.async(['./showTable','./search'],function(showTable,search){
			showTable.ajaxUrl('/member/borrow/repaymentList.html?'+window.location.search.substr(1),tpl);
			search.search('/member/borrow/repaymentList.html?',tpl);
		});
	}
	else
	{
		require.async(['./showTable','./search'],function(showTable,search){
		showTable.ajaxUrl('/member/borrow/repaymentList.html?status='+99,tpl);
		search.search('/member/borrow/repaymentList.html?',tpl);
	});
	}
	
	//还款
	$("#toPayBtn").live("click",function(){
		var idVal = $(this).attr("data-val");
		window.open("/invest/repaySkip.html?repaymentId="+idVal);
		//构造确认框DOM
		layer.open({
		    type: 1,
		    closeBtn: 0,
		    title: false,
		    area: ['220px', '100px'],
		    shade: [0.5, '#000'],
		    border: [10, 0.3, '#000'],
		    content: '<div class="fileconfirm"><span><i class="iconfont">&#xe614;</i>请选择操作？</span><div class="fileconfirmbtn"><a href="javascript:;" class="okBtn">还款成功</a><a href="javascript:;"  class="cancleBtn">还款失败</a></div></div>'
		});	
		//确认操作
		$(".okBtn").click(function(){
			$.ajax({
				url:"/themes/theme_default/media/json/msg.json",
				dataType:"json",
				success: function(data){

					//单点登录检测
					if(Auth.checkLogin(arguments[0]) == false) {return ;}
					if(json.result==false&&json.msg!=undefined){
						layer.open({
							type: 1,
				            closeBtn:1,
				            title: "&nbsp;",
				            area: ['384px', '186px'],
				            border: [1, 1, '#cecfd0'],
				            content: '<div class="tipsWrap w384"><div class="tipsTxt"><i class="iconfont errIco">&#xe63e;</i><span>'+json.msg+'</span></div><div class="tipsBtnBar"><a href="javascript:;" class="okBtn failBtn">确定</a></div></div>'
				        }); 
						return;
					}

					if(data.result){
						location.reload();
					}						
				}			
			});				
		});
		//删除操作
		$(".cancleBtn").click(function(){
			layer.closeAll();
		});
	})
	
	//弹窗控件
/*	function repay(url){
			layer.prompt({title: '请输入交易密码',type: 1}, function(pass){
			$.ajax({
				type:"post",
				url:url + '&payPwd=' + pass,
				dataType:"json",
				success:function(data){
					if(!data.result){
						layer.msg(data.msg, 2, function(){});
					}else{
						layer.msg('还款成功', 2, function(){
						    location.reload();
						});
					}
				}
			});
		})
	}*/
});